package com.sfh.cp;

import android.content.Context;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.sfh.lib.AbstractApplication;
import com.sfh.lib.AppCacheManager;
import com.tencent.bugly.Bugly;

import java.util.List;

import cn.bmob.v3.Bmob;
import crm.sfh.server.Const;

/**
 * 功能描述:
 *
 * @author SunFeihu 孙飞虎
 * @date 2018/5/1
 */
public class AppContext extends AbstractApplication {



    @Override
    public String getPreFile() {
        return "Pre.pre";
    }

    @Override
    public String getCachePath() {
        return "cp";
    }

    @Override
    public String getCrashReport() {
        return "fe698b2146";
    }

    @Override
    public void onCreate() {
        super.onCreate();
        //第一：默认初始化
        Bmob.initialize(this, "bda6805a94158167cb51f743e17fcff2");
        getLocationListener(this, new AMapLocationListener() {
            @Override
            public void onLocationChanged(AMapLocation amapLocation) {
                if (amapLocation != null && amapLocation.getErrorCode() == 0) {
                    //可在其中解析amapLocation获取相应内容。
                    AppCacheManager.newInstance().putCache(false, Const.CITY, amapLocation.getCity());
                }
            }
        });
    }

    @Override
    public void onLoseToken(String s) {

    }

    public static void getLocationListener(Context context, AMapLocationListener mLocationListener) {
        AMapLocationClient mLocationClient = new AMapLocationClient(context.getApplicationContext());
        //设置定位回调监听
        mLocationClient.setLocationListener(mLocationListener);
        AMapLocationClientOption mLocationOption = new AMapLocationClientOption();
        //设置定位模式为AMapLocationMode.Hight_Accuracy，高精度模式。
        mLocationOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
        //获取一次定位结果：
        mLocationOption.setOnceLocation(true);
        //设置是否允许模拟位置,默认为true，允许模拟位置
        mLocationOption.setMockEnable(true);
        //给定位客户端对象设置定位参数
        mLocationClient.setLocationOption(mLocationOption);
        //启动定位
        mLocationClient.startLocation();

    }

}
